const app = getApp()
const WXAPI = require("../../../../api/newApi")
const WXAPIOLD = require("../../../../api/api")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputTxt:'',
    isShow: false,
    searchName: '',//搜索信息
    information:{},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      statusHeight: app.gettop.height,
      status: app.gettop.status,
      navHeight:app.gettop.navHeight,
      mobbleBottom: app.mobile.mobbleBottom
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  back(){
    wx.navigateBack({
      delta: 0,
    })
  },
  bindinput(e){
    console.log(e.detail.value)
    if(e.detail.value!=''){
      this.setData({
        isShow: true
      })
    }else{
      this.setData({
        isShow: false
      })
    }
    this.data.searchName = e.detail.value
  },
  clickClose(){
    this.setData({
      inputTxt: '',
      isShow: false
    })
  },
  sumit(){ //确定 customerInfo
    wx.showLoading({
      title: '加载中',
    })
     var data = {
      searchName: this.data.searchName,
    }
    WXAPI.customerInfo(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        wx.hideLoading({})
        if(res.result==''){
          wx.showToast({
            title: '用户不存在',
            icon:'none'
          })
        }else{
          this.data.information = JSON.stringify(res.result)
          console.log(this.data.information)
          wx.navigateTo({
            url: '/userPageA/pages/scan/information/information?info=' + this.data.information,
          })
        }
       
      }
    })
    
  },
  //唤醒扫一扫功能
  getScancode: function() {
    var that = this;
    // 允许从相机和相册扫码
    wx.scanCode({
      success: (res) => {
        console.log(res.result)
        let parameter = res.result.split("code=")[1];
        console.log(parameter)
        let result = JSON.parse(parameter)

        console.log(result)
        console.log("扫一扫参数",result.param)
        console.log("扫一扫类型",result.type)
        if(result.type==1){
          wx.navigateTo({
            url: '/userPageA/pages/scan/information/information?param=' + result.param
          })
        }else if(result.type==2){
          wx.navigateTo({
            url: '/userPageA/pages/scan/receiving_assets/receiving_assets?param=' + result.param
          })
        }else if(result.type==4){
          this.setData({
            qrCodeUrl: result.param,
          })
          this.getParCollectionQrCodeUrl()
        }
        else{
          console.log('else')
        }
      },
      fail:(res)=>{
        console.log(res)
      }
    })
  },
  //解析二维码confirmInfo
  getParCollectionQrCodeUrl(){
   
    var data = {
      qrCodeUrl:this.data.qrCodeUrl,
      // qrCodeUrl:'https://bee.xiaodaiyan.com/pay/uQRxY%2F6Y4pbfVN4%2BbISi5WEG2fcys%2Beg9h2%2B0dfXuU8%3D',
    }
    WXAPIOLD.parCollectionQrCodeUrl(data, (res) =>{
      const data = res.result
      console.log("解析二维码",res)
      if(res.code === 200){
        var merchantId = data.merchantId
        wx.navigateTo({
          url: '/pages/pay/pay?QRmerchantId='+merchantId,
        })
      }else{
        wx.showToast({
          title: '无效收款码',
          icon: 'none'
        })
      }
    })
  },
})